import React from 'react'
// ===================================================================== Temp
import FormModal from '#cpt/temp/FormModal'
// ===================================================================== global declare
const { $fn, $Lazy, $http } = window
// ===================================================================== Lazy
const $cache 	= $Lazy.file(()=>import('#private/cache-api'))
const confirm 	= $Lazy.file(()=>import('@antd/confirm'))
// ===================================================================== component
class Index extends React.Component{
	state = {
		data:[],
		pag: {},
		selectedKeys:[],
		//修改账期
		formData:[
			{ label: '医院名称',		name: 'hosp_name', 	half:true, disabled:true },
			{ label: '模板名称',		name: 'qt_temp_id', 	half:true, type: 'select', 	loading:true, idStr:'uuid',
				onValue:({rows})=>{
					this.model.qt_temp_name = rows ? rows.name : ''
				}
			 },
		]
	}
	submit = {}
	model = {}
	query = {}
	open = async ({ hosp_name, hosp_id }) => {
		const { temp_name } =  $fn.query()
		this.query = { temp_name:$fn.decode(temp_name) }
		this.modal.open({ formRef:this.formRef })
		this.submit = { hosp_id, hosp_name }
		this.getModalSelect()
		this.formRef.setValue({ hosp_name })
	}
	
	// 获取弹窗下拉框数据
	getModalSelect = async () => {
		const { formData } = this.state
		$fn.setModalRows(formData, 'qt_temp_id', ()=>{
			$cache.then( async f => {
				// 模板名称
				await $fn.setRowc(formData, 'qt_temp_id',  async () =>  f.getCache({ api: 'qt_template'}))
				//
				this.setState({ formData })
			})
		})
	}
	
	render(){
		// return FormModal.call(this,{ title:'医院物价模板导入', api: 'qt-item-hospital/bindtemp', okText:'绑定模板', isConfirm:true})
		return FormModal.call(this,{ title:'医院物价模板导入', okText:'绑定模板', onOk:() => {
			confirm.then(f=>{
				f({
					msg:this.query?.temp_name !== 'undefined' && this.query?.temp_name ? `【${this.model.qt_temp_name}】会覆盖【${this.query?.temp_name}】模板物价，是否确认?`:`【${this.model.qt_temp_name}】会覆盖物价，是否确认?`,
					onOk: close => {
						const param = this.formRef.getValue()
						$http.submit(null,'qt-item-hospital/bindtemp',{param:{...param,...this.submit}}).then(()=>{
							close()
							this.modal.close()
						})
					}
				})
			})
		},
		onComplete:()=> $fn.dataRemove('qt-comp-template/select')
	})
	}
}

export default Index